package sample;

import java.awt.SystemTray;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class ChooseExitType {
    public ChooseExitType() {
    }

    public static void choose(final Stage stage) {
        try {
            final Stage dialogStage = new Stage();
            dialogStage.initOwner(stage);
            Scene scene = new Scene(new Group());
            dialogStage.setWidth(250.0D);
            dialogStage.setHeight(150.0D);
            dialogStage.setResizable(false);
            final ToggleGroup group = new ToggleGroup();
            RadioButton rb1 = new RadioButton("最小化到系统托盘，不退出程序");
            rb1.setToggleGroup(group);
            rb1.setUserData("1");
            RadioButton rb2 = new RadioButton("退出程序");
            rb2.setToggleGroup(group);
            rb2.setUserData("2");
            group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
                @Override
                public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
                    if (group.getSelectedToggle() != null) {
                        if (group.getSelectedToggle().getUserData().toString().equals("1")) {
                            Platform.setImplicitExit(false);
                            stage.hide();
                            dialogStage.hide();
                        } else {
                            SystemTray.getSystemTray().remove(TrayUtil.getTrayIcon());
                            Platform.exit();
                        }
                    }

                }
            });
            HBox hbox = new HBox();
            VBox vbox = new VBox();
            vbox.getChildren().add(rb1);
            vbox.getChildren().add(rb2);
            vbox.setSpacing(10.0D);
            hbox.getChildren().add(vbox);
            hbox.setSpacing(50.0D);
            hbox.setPadding(new Insets(20.0D, 10.0D, 10.0D, 20.0D));
            ((Group)scene.getRoot()).getChildren().add(hbox);
            dialogStage.setScene(scene);
            dialogStage.show();
        } catch (Exception var8) {
            var8.printStackTrace();
        }

    }
}
